home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WINSRC20.ZIP
/
WINDOS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-22
|
27KB
|
910 lines
/*
Routines which simulate DOS functions in the existing
Fractint for DOS
*/
#include "windows.h"
#include "fractint.h"
#include "winfract.h"
#include <time.h>
#include <stdio.h>
int save_system; /* tag identifying Fractint for Windows */
int save_release; /* tag identifying version number */
int win_release = 200; /* tag identifying version number */
char win_comment[] = /* "About..." comment */
{" "}; /* publicly-released version */
/* {"Test Version - Not for Release"}; interim test versions */
extern BOOL bTrack; /* TRUE if user is selecting a region */
extern BOOL zoomflag; /* TRUE is a zoom-box selected */
extern HWND hwnd; /* handle to main window */
extern int xdots, ydots, colors, maxiter;
extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
extern int win_xdots, win_ydots;
extern int last_written_y; /* last line written */
extern int screen_to_be_cleared; /* clear screen flag */
extern int time_to_act; /* time to take some action? */
extern int time_to_restart; /* time to restart? */
extern int time_to_quit; /* time to quit? */
extern int time_to_reinit; /* time to reinitialize? */
extern int time_to_load; /* time to load? (DECODE) */
extern int time_to_save; /* time to save? (ENCODE) */
extern int time_to_print; /* time to print? (PRINTER) */
extern int time_to_cycle; /* time to begin color-cycling? */
extern unsigned char dacbox[256][3];
extern BOOL win_systempaletteused; /* flag system palette set */
extern unsigned char far temp_array[]; /* temporary spot for Encoder rtns */
extern HANDLE hpixels; /* handle to the DIB pixels */
extern unsigned char huge *pixels; /* the device-independent bitmap pixels */
int pixels_per_byte; /* pixels/byte in the pixmap */
long pixels_per_bytem1; /* pixels / byte - 1 (for ANDing) */
int pixelshift_per_byte; /* 0, 1, 2, or 3 */
int bytes_per_pixelline; /* pixels/line / pixels/byte */
extern int kbdcount;
extern int win_overlay3d;
extern int win_display3d;
/****************************************************************************
FUNCTION: keypressed(), getakey()
PURPOSE:
keypressed()
Checks for, and processes, messages.
Returns -1 if it's time to wrap up and go home.
Returns 0 otherwise.
getakey()
same, but doesn't return until it's time to.
****************************************************************************/
BOOL dont_wait_for_a_key = TRUE;
int getakey()
{
int i;
dont_wait_for_a_key = FALSE;
i = keypressed();
dont_wait_for_a_key = TRUE;
zoomflag = FALSE;
return(i);
}
int keypressed()
{
MSG msg;
if (dont_wait_for_a_key)
if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
time_to_act = time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle;
/* bail out if nothing is happening */
return(time_to_act);
}
while (GetMessage(&msg, NULL, NULL, NULL)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
if (!bTrack) { /* don't do this if mouse-button is down */
time_to_act = time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle;
if (dont_wait_for_a_key || time_to_act)
return(time_to_act);
}
}
if (!dont_wait_for_a_key)
time_to_quit = 1;
/* bail out if nothing is happening */
time_to_act = time_to_reinit+time_to_restart+time_to_quit+
time_to_load+time_to_save+time_to_print+time_to_cycle;
return(time_to_act);
}
/****************************************************************************
FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
PURPOSE:
putcolor:
sets the "color" value of the pixel at location x,y
(actually, a palette value)
getcolor:
returns the "color" value of the pixel at location x,y
(actually, a palette value)
****************************************************************************/
extern int debug_fastupdate;
time_t last_time;
time_t update_time;
long minimum_update;
long pixelsout;
int top_changed, bottom_changed;
static unsigned char win_andmask[8];
static unsigned char win_notmask[8];
static unsigned char win_bitshift[8];
void putcolor(int x, int y, int color)
{
RECT tempRect; /* temporary rectangle structure */
long i;
int j, tempcolor, temp_top_changed, temp_bottom_changed;
time_t this_time;
kbdcount--; /* partially adjust for the lower speed of Win graphics */
last_written_y = y;
if (y < top_changed) top_changed = y;
if (y > bottom_changed) bottom_changed = y;
i = win_ydots-1-y;
i = (i * win_xdots) + x;
if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
if (pixelshift_per_byte == 0) {
pixels[i] = color % colors;
}
else {
unsigned int j;
j = i & pixels_per_bytem1;
i = i >> pixelshift_per_byte;
pixels[i] = (pixels[i] & win_notmask[j]) +
(((unsigned char)(color % colors)) << win_bitshift[j]);
}
/* check the time every nnn pixels */
if (debug_fastupdate || ++pixelsout > 100) {
pixelsout = 0;
this_time = time(NULL);
/* time to update the screen? */
if (debug_fastupdate || (this_time - last_time) > update_time ||
(minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
temp_top_changed = top_changed - win_yoffset;
temp_bottom_changed = bottom_changed - win_yoffset;
if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
if (temp_top_changed < 0) temp_top_changed = 0;
if (temp_bottom_changed < 0) temp_bottom_changed = 0;
tempRect.top = temp_top_changed;
tempRect.bottom = temp_bottom_changed+1;
tempRect.left = 0;
tempRect.right = xdots;
InvalidateRect(hwnd, &tempRect, FALSE);
keypressed(); /* force a look-see at the screen */
}
last_time = this_time;
top_changed = win_ydots;
bottom_changed = 0;
}
}
}
}
int getcolor(int x, int y)
{
long i;
i = win_ydots-1-y;
i = (i * win_xdots) + x;
if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
if (pixelshift_per_byte == 0) {
return(pixels[i]);
}
else {
unsigned int j;
j = i & pixels_per_bytem1;
i = i >> pixelshift_per_byte;
return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
}
}
else
return(0);
}
int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
{
int i, len;
long startloc;
len = rightpt - leftpt;
if (rightpt >= xdots) len = xdots - 1 - leftpt;
startloc = win_ydots-1-rownum;
startloc = (startloc * win_xdots) + leftpt;
kbdcount -= (len>>2); /* adjust for the lower speed of Win graphics */
if (rownum < 0 || rownum >= ydots || leftpt < 0) {
return(0);
}
if (pixelshift_per_byte == 0) {
for (i = 0; i <= len; i++)
pixels[startloc+i] = localvalues[i];
}
else {
unsigned int j;
long k;
for (i = 0; i <= len; i++) {
k = startloc + i;
j = k & pixels_per_bytem1;
k = k >> pixelshift_per_byte;
pixels[k] = (pixels[k] & win_notmask[j]) +
(((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
}
}
pixelsout += len;
putcolor(leftpt, rown